#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/*
 * Copyright © 2014, Finium Sdn Bhd, All Rights Reserved
 * 
 * BaseTestCase.java
 * Modification History
 * *************************************************************
 * Date				Author						Comment
 * Mar 02, 2012		Venkaiah Chowdary Koneru	Created
 * *************************************************************
 */
package ${package}.test;

import java.io.IOException;
import java.sql.SQLException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;

import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.ServerSetupTest;

/**
 * Base class for unit tests with spring context.
 * <p>
 * Each method is run within a transaction which is rolled back when method is
 * over.
 * </p>
 * 
 * @author Venkaiah Chowdary Koneru
 * @see TransactionConfiguration
 * @see ContextConfiguration
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext-test.xml" })
@TransactionConfiguration(defaultRollback = true,
        transactionManager = "transactionManager")
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public abstract class BaseTestCase
{
    @Autowired
    private static ApplicationContext applicationContext;
    
    private static GreenMail greenMail;
    
    /**
     * to be run before every Test method.
     * 
     * @throws IOException
     * @throws SQLException
     *             in case of errors
     */
    @BeforeClass
    public static void setupContext() throws SQLException, IOException
    {
        UtilTestCase.setupContext();
        
        greenMail = new GreenMail(ServerSetupTest.SMTP);
        greenMail.start();
    }

    /**
     * to be run after every Test method
     * 
     * @throws SQLException
     * @throws IOException
     *             in case of errors
     */
    @AfterClass
    public static void afterTestMethod() throws SQLException, IOException
    {
        UtilTestCase.afterTestMethod();
        
        greenMail.stop();
    }
}
